{{define "Title"}}Query By Date{{end}}
{{define "Content"}}

<script type=text/javascript src="/js/exportToExcel.js"></script>
<script type=text/javascript src="/js/calendar.js"></script>
<script type=text/javascript src="/js/tablestyle.js"></script>

<div class="container-fluid">
<form class="form-horizontal" action="/querybydate" method="POST">
  <fieldset>
    <legend><b>Query By Date</b></legend>
    {{if .error}}<div class="alert alert-error"><b>Error: </b>{{.error | html}}</div>
    {{end}}
    <div class="control-group">
      <label class="control-label">Begin Date&nbsp;</label>
      <div class="control">
        <input class="input-large" id="fromdate" name="fromdate" style="background-color: #FFFFD0" onfocus="setday(this);" size="20"> <b style="color: red">*</b>
      </div>
    </div>
    <div class="control-group">
      <label class="control-label">End Date&nbsp;</label>
      <div class="control">
        <input class="input-large" id="todate" name="todate" style="background-color: #FFFFD0" onfocus="setday(this);" size="20"> <b style="color: red">*</b>
      </div>
    </div>
    <div class="control-group">
      <label class="control-label">Item&nbsp;</label>
      <div class="control">
        <select id="item" name="item" onkeydown="clicka();">
          <option value="">
          {{range .items}}
            <option value="{{.Item | html}}">{{.Item | html}}  |  {{.Desc | html}}
          {{end}}
        </select>
      </div>
    </div>
    <div class="control-group">
      <label class="control-label">Work Order&nbsp;</label>
      <div class="control">
        <input type="text" class="input-large" id="wono" name="wono" style="text-transform:uppercase;" maxlength="30">
      </div>
    </div>
    <div class="form-actions">
      <button type="submit" class="btn btn-primary">Query</button>
    </div>
    {{if .dict_rst}}
      <div class="control">
        <input type=button class="btn btn-primary" id="toexcel" value="Export to Excel" onclick="getXlsFromTbl('tbl_ls', null);">
      </div>
    {{end}}
  </fieldset>
</form>
</div>

{{if .dict_rst}}
<div class="control-group">
  <label class="control-label">Query Date Range: <b>{{.from_datetime | html}} - {{.to_datetime  | html}}</b></label>
</div>
<div class="control-group">
  <label class="control-label">Item: <b>{{.item  | html}}</b></label>
</div>
<div class="control-group">
  <label class="control-label">Work Order: <b>{{.wono  | html}}</b></label>
</div>

<div class="content-box">
  <div class="content-box-header">
    <p style="font-size: 16px;">&nbsp;&nbsp;<b>Report Detail</b></p>
  </div>
<table id="tbl_ls" border="1" cellspacing="0" cellpadding="0" style="font-size:100%">
  <thead>
    <tr>
      <th rowspan='2' style="text-align:center">Item</th>
      <th rowspan='2' style="text-align:center">Station</th>
      <th colspan='3' style="text-align:center">Pass Yield</th>
      <th colspan='3' style="text-align:center">First Pass Yield</th>
    </tr>
    <tr>
      <td>PASS</td>
      <td>FAIL</td>
      <td>PY</td>
      <td>PASS</td>
      <td>FAIL</td>
      <td>FPY</td>
    </tr>
  </thead>
  <tbody id="group_one">
  {{$curwo := .wono | html}}
  {{$curfrom := .from_datetime | html}}
  {{$curto := .to_datetime | html}}
  {{range .dict_rst}}
    {{$curls := .}}
    <tr>
      <th rowspan="{{$curls.Leng}}" style="text-align:center">{{$curls.Item | html}}: {{$curls.Desc | html}}</th>
    </tr>
    {{range $sta, $data := $curls.Data}}
      <tr>
        <th style="text-align:center">{{$sta | html}}</th>
        {{if index $data 0}}
          <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px"><a href="/datedetail?nm={{index $data 0 | html}}&fd={{$curfrom | html}}&td={{$curto | html}}&im={{$curls.Item | html}}&wo={{$curwo | html}}&st={{$sta | html}}&tp=PY&ts=PASS">{{index $data 0 | html}}</a></td>
        {{else}}
          <td fieldset style="color: #666666; border-style: groove; font-size: 14px">0</td>
        {{end}}
        {{if index $data 1}}
          <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px"><a href="/datedetail?nm={{index $data 1 | html}}&fd={{$curfrom | html}}&td={{$curto | html}}&im={{$curls.Item | html}}&wo={{$curwo | html}}&st={{$sta | html}}&tp=PY&ts=FAIL">{{index $data 1 | html}}</a></td>
        {{else}}
          <td fieldset style="color: #666666; border-style: groove; font-size: 14px">0</td>
        {{end}}
        <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px">{{index $data 2 | html}}</td>

        {{if index $data 3}}
          <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px"><a href="/datedetail?nm={{index $data 3 | html}}&fd={{$curfrom | html}}&td={{$curto | html}}&im={{$curls.Item | html}}&wo={{$curwo | html}}&st={{$sta | html}}&tp=FPY&ts=PASS">{{index $data 3 | html}}</a></td>
        {{else}}
          <td fieldset style="color: #666666; border-style: groove; font-size: 14px">0</td>
        {{end}}
        {{if index $data 4}}
          <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px"><a href="/datedetail?nm={{index $data 4 | html}}&fd={{$curfrom | html}}&td={{$curto | html}}&im={{$curls.Item | html}}&wo={{$curwo | html}}&st={{$sta | html}}&tp=FPY&ts=FAIL">{{index $data 4 | html}}</a></td>
        {{else}}
          <td fieldset style="color: #666666; border-style: groove; font-size: 14px">0</td>
        {{end}}
        <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px">{{index $data 5 | html}}</td>
      </tr>
    {{end}}
    <tr>
      <th style="text-align:center"><B>Subtotal</B></th>
      {{if gt $curls.SubPyPass 0}}
        <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px"><a href="/datedetail?nm={{$curls.SubPyPass | html}}&fd={{$curfrom | html}}&td={{$curto | html}}&im={{$curls.Item | html}}&wo={{$curwo | html}}&st=Subtotal&tp=PY&ts=PASS">{{$curls.SubPyPass | html}}</a></td>
      {{else}}
        <td fieldset style="color: #666666; border-style: groove; font-size: 14px">0</td>
      {{end}}
      {{if gt $curls.SubPyFail 0}}
        <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px"><a href="/datedetail?nm={{$curls.SubPyFail | html}}&fd={{$curfrom | html}}&td={{$curto | html}}&im={{$curls.Item | html}}&wo={{$curwo | html}}&st=Subtotal&tp=PY&ts=FAIL">{{$curls.SubPyFail | html}}</a></td>
      {{else}}
        <td fieldset style="color: #666666; border-style: groove; font-size: 14px">0</td>
      {{end}}
      <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px">{{$curls.SubPy | html}}</td>

      {{if gt $curls.SubFpyPass 0}}
        <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px"><a href="/datedetail?nm={{$curls.SubFpyPass | html}}&fd={{$curfrom | html}}&td={{$curto | html}}&im={{$curls.Item | html}}&wo={{$curwo | html}}&st=Subtotal&tp=FPY&ts=PASS">{{$curls.SubFpyPass | html}}</a></td>
      {{else}}
        <td fieldset style="color: #666666; border-style: groove; font-size: 14px">0</td>
      {{end}}
      {{if gt $curls.SubFpyFail 0}}
        <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px"><a href="/datedetail?nm={{$curls.SubFpyFail | html}}&fd={{$curfrom | html}}&td={{$curto | html}}&im={{$curls.Item | html}}&wo={{$curwo | html}}&st=Subtotal&tp=FPY&ts=FAIL">{{$curls.SubFpyFail | html}}</a></td>
      {{else}}
        <td fieldset style="color: #666666; border-style: groove; font-size: 14px">0</td>
      {{end}}
      <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px">{{$curls.SubFpy | html}}</td>
    </tr>
  {{end}}
  {{$curls := .alltotal}}
  <tr>
    <th rowspan="2" colspan="2" style="text-align:center"><B>Total</B></th>
  </tr>
  <tr>
    {{if gt $curls.SubPyPass 0}}
      <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px"><a href="/datedetail?nm={{$curls.SubPyPass | html}}&fd={{$curfrom | html}}&td={{$curto | html}}&im=All&wo={{$curwo | html}}&st=Subtotal&tp=PY&ts=PASS">{{$curls.SubPyPass | html}}</a></td>
    {{else}}
      <td fieldset style="color: #666666; border-style: groove; font-size: 14px">0</td>
    {{end}}
    {{if gt $curls.SubPyFail 0}}
      <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px"><a href="/datedetail?nm={{$curls.SubPyFail | html}}&fd={{$curfrom | html}}&td={{$curto | html}}&im=All&wo={{$curwo | html}}&st=Subtotal&tp=PY&ts=FAIL">{{$curls.SubPyFail | html}}</a></td>
    {{else}}
      <td fieldset style="color: #666666; border-style: groove; font-size: 14px">0</td>
    {{end}}
    <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px">{{index $curls.SubPy | html}}</td>

    {{if gt $curls.SubFpyPass 0}}
      <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px"><a href="/datedetail?nm={{$curls.SubFpyPass | html}}&fd={{$curfrom | html}}&td={{$curto | html}}&im=All&wo={{$curwo | html}}&st=Subtotal&tp=FPY&ts=PASS">{{$curls.SubFpyPass | html}}</a></td>
    {{else}}
      <td fieldset style="color: #666666; border-style: groove; font-size: 14px">0</td>
    {{end}}
    {{if gt $curls.SubFpyFail 0}}
      <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px"><a href="/datedetail?nm={{$curls.SubFpyFail | html}}&fd={{$curfrom | html}}&td={{$curto | html}}&im=All&wo={{$curwo | html}}&st=Subtotal&tp=FPY&ts=FAIL">{{$curls.SubFpyFail | html}}</a></td>
    {{else}}
      <td fieldset style="color: #666666; border-style: groove; font-size: 14px">0</td>
    {{end}}
    <td fieldset style="color: #666666; border-style: groove; font-weight: bold; font-size: 14px">{{$curls.SubFpy | html}}</td>
  </tr>
  </tbody>
</table>
</div>
{{end}}

{{end}}